<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class site
{
    // Public properties
    public $settings = array();
    // Protected or private properties
    protected $_table;
    
    // Constructor
    public function __construct()
    {
        if (!isset($this->CI))
        {
            $this->CI =& get_instance();
        }
        $this->CI->load->library('user_agent');
        //$this->get_site_info();
    }
	
    public function load($page, $data = NULL,$layout=FALSE)
    {
		$data['page'] = $page;
		
		// load template
		if($layout==TRUE){
			$this->CI->load->view('html/skin_'.$layout, $data);
		}else{
			$this->CI->load->view('html/skin', $data);
		}        
    }

	// Phan danh cho SEO meta
	function get_meta_tag()
	{
		$url = isset($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] : $_SERVER["REQUEST_URI"];
		$uri = explode("/", $url) ;
		
		$id = (int) str_replace(".html","", end($uri)) ;
		
		if(strpos($url, 'category') > 0 )
		{
			$this->CI->db->where("proid",$id) ;
			$this->CI->db->where("kind",'category') ;
			$query = $this->CI->db->get("seo");
		}
		else if (strpos($url, 'product') > 0)
		{ 
			$this->CI->db->where("proid",$id) ;
			$this->CI->db->where("kind",'product') ;
			$query = $this->CI->db->get("seo");
		}
		else
		{
			$this->CI->db->where("sid", 1) ;
			$query = $this->CI->db->get("seo");
		}
		
		return $query->row() ;
		
	}
	
	function get_default_meta()
	{
		$this->CI->db->where("sid", 1) ;
		$query = $this->CI->db->get("seo");
		return $query->row() ;
	}
	// Phan danh cho admin
    public function loadadmin($page, $data = NULL)
	{
        $data['page'] = $page;
        $this->CI->load->view('theme/admin/vnit/skin', $data);        
    }
	
    // Get Templates Active
    public function get_default_template()
    {
        $this->CI->db->select('duongdan');
        $this->CI->db->where('kichhoat', '1');
        
        $query = $this->CI->db->get('giaodien', 1);
        
        if ($query->num_rows() == 1)
        {
            $row = $query->row_array();
        }
        
        return $row['duongdan'];
    }
    
    public function get_default_language()
    {
        $this->CI->db->select('language');
        $this->CI->db->where('is_default', '1');
        
        $query = $this->CI->db->get($this->_table['languages'], 1);
        
        if ($query->num_rows() == 1)
        {
            $row = $query->row_array();
        }
        
        return $row['language'];
    }
    
}
?>